var selectName ;
// 定时刷新页面获取手持气象站数据
//function myrefresh() { 
//	selectName = document.getElementById("select").value;
	// alert("0 selectname = " + selectName)
//	window.location.reload();
//} 
//setTimeout('myrefresh()',60000); //指定60秒刷新一次

var app = angular.module('zth',[]);
app.controller('qxzController',function($scope,$http,$interval){
	// var time = window.setInterval('show(selectName)',5000);
	//获取气象站相关数据
	// 打开串口
	$scope.start=function(selectName){
		// alert(selectName);
		if(selectName!=null && selectName !=""){
			$http.get('start.do?name=' + selectName).success(
				function (response){
					document.getElementById("start").style.display="none";
					document.getElementById("close").style.display="inline"; 
					if(response !=null)
						document.getElementById("conn1").style.display="none";
					//document.getElementById("start").style.display="inline";
					$scope.start=response;  
				}
			);
		}else{
			alert("请选择您要连接的串口！");
		}
	} 
	
	// 关闭串口
	$scope.close=function(){
		$http.get('close.do').success(
			function (response){ 
				alert(response);
				document.getElementById("close").style.display="none";
				document.getElementById("start").style.display="inline";
				window.location.reload();
				$scope.close=response; 
			}
		);
	}
	
	// 获取所有端口信息
	$scope.findPorts=function(){
		$http.get('findPorts.do').success(
			function (response){ 
				$scope.list=response;  
			}
		);
	}
	// 定时器
	$interval(function(){
        $http.get('showTh01.do').success(
            function (response){
                $scope.qxzTh=response;
                if($scope.qxzTh.dianya != null) document.getElementById("work1").style.display="none";
                if($scope.qxzTh.time != null) document.getElementById("get1").style.display="none";

                if($scope.qxzTh.wendu != null)document.getElementById("wd1").style.display="none";
                if($scope.qxzTh.shidu != null)document.getElementById("sd1").style.display="none";
                if($scope.qxzTh.qiya != null)document.getElementById("qy1").style.display="none";

                //if($scope.qxz.houfengxiangjiaodu != null)document.getElementById("fx1").style.display="none";
                //if($scope.qxz.fengsu != null)document.getElementById("fs1").style.display="none";
                //if($scope.qxz.yuliang != null)document.getElementById("yl1").style.display="none";
            }
        );

		// $http.get('show.do').success(
		// 	function (response){
		// 		$scope.qxz=response;
		// 		if($scope.qxz.dianya != null) document.getElementById("work1").style.display="none";
		// 		if($scope.qxz.time != null) document.getElementById("get1").style.display="none";
		// 		if($scope.qxz.xinhaoqiangdu != null) document.getElementById("signal1").style.display="none";
		//
		// 		if($scope.qxz.wendu != null)document.getElementById("wd1").style.display="none";
		// 		if($scope.qxz.shidu != null)document.getElementById("sd1").style.display="none";
		// 		if($scope.qxz.qiya != null)document.getElementById("qy1").style.display="none";
		//
		// 		//if($scope.qxz.houfengxiangjiaodu != null)document.getElementById("fx1").style.display="none";
		// 		//if($scope.qxz.fengsu != null)document.getElementById("fs1").style.display="none";
		// 		//if($scope.qxz.yuliang != null)document.getElementById("yl1").style.display="none";
		// 	}
		// );
	},60000,-1);
	
	 // 计时器
	$interval(function(){
        var time = new Date(); 
        var hh = time.getHours();            //时
        var mm = time.getMinutes();          //分
        var ss = time.getSeconds();			 //秒 
        if (hh < 10) hh = "0" + hh; 
        if (mm < 10) mm = "0" + mm;  
        if (ss < 10) ss = "0" + ss; 
        var t = time.getFullYear()+"-"+(time.getMonth()+1)+"-"+time.getDate() + " "+hh +":"+mm+":"+ss + " 星期"+"日一二三四五六".charAt(time.getDay());
        $scope.time = t; 
        
    },1000);
	
	
});

// 关闭页面
function closePage() {
    if (navigator.userAgent.indexOf("MSIE") > 0) {
         if (navigator.userAgent.indexOf("MSIE 6.0") > 0) {
              window.opener = null; window.close();
         } else {
              window.open('', '_top'); window.top.close();
         }
    } else if (navigator.userAgent.indexOf("Firefox") > 0) {
        window.location.href = 'about:blank '; //火狐默认状态非window.open的页面window.close是无效的
        //window.history.go(-2);
    } else {
        window.opener = null;
        window.open('', '_self', '');
        window.close();
    }
}

//全屏
function fullScreen(){
	document.getElementById("full").style.display="none";
	document.getElementById("exit").style.display="inline";
    var el = document.documentElement;
    var rfs = el.requestFullScreen || el.webkitRequestFullScreen || el.mozRequestFullScreen || el.msRequestFullscreen;      
    if(typeof rfs != "undefined" && rfs) {
        rfs.call(el);
    };
    return;
}

//退出全屏
function exitScreen(){
	document.getElementById("exit").style.display="none";
	document.getElementById("full").style.display="inline";
    if (document.exitFullscreen) {  
        document.exitFullscreen();  
    }  
    else if (document.mozCancelFullScreen) {  
        document.mozCancelFullScreen();  
    }  
    else if (document.webkitCancelFullScreen) {  
        document.webkitCancelFullScreen();  
    }  
    else if (document.msExitFullscreen) {  
        document.msExitFullscreen();  
    } 
    if(typeof cfs != "undefined" && cfs) {
        cfs.call(el);
    }
} 